<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
  
    <common-head></common-head>
  </div>
  <script src="./vue.js"></script>
  <script>
    // 定义一个混入
    const mixin = {
      data(){
        return {
          msg: '混入上的数据'
        }
      },
      methods:{
        changeMsg(){
          this.msg = '值改变了';
        }
      },
      watch: {
        msg(){
          console.log('msg数据改变了');
        }
      }
    };
    const CommonHead = {
      template: `
        <div>
          <h1>我是公共头部</h1> 
          <button @click="changeMsg">按钮</button>
          {{ msg }}
        </div>
      `,
      mixins: [mixin],
      data(){
        return {
          msg:'组件上的数据'
        }
      },
      mounted(){
        console.log(this);
      }
    };
    Vue.component('CommonHead', CommonHead)
    const vm = new Vue({
      el: '#app'
    })
  </script>
</body>
</html>